jsx3.Class.defineClass(
	"tibco.admin.monitormanage.general.PageBusUtils",                   // the full name of the class to create
    jsx3.lang.Object, //  extends
	null,  // does not implement an interface
	function(pageBusUtil) {
	
	    pageBusUtil.pageBusJSS = "org.pagebus.msg.Message";
        pageBusUtil.pageBusMessageVersion = "0.9.2";
        pageBusUtil.subscriptionList = null;

        /**
         *  Not for public consumption
         */
        pageBusUtil.getNamespace = function() {
        	return "tibco.admin";
        }

        /**
         *  Not for public consumption
         */
	pageBusUtil.getPageBus = function() {
          	if(!window || !window.PageBus)
           	{ tibco.admin.Main.loadClass("tibco/admin/monitormanage/resources/pageBus/pagebus.js", pageBusUtil.getNamespace()); }
           	return window.PageBus;
        }
        
        /**
         *  Publishes a message on the subject in the correct format
         *  @param subject the subject to post the message to
         *  @param message the message to be sent
         */
        pageBusUtil.publish = function(subject, message) {
        	if(subject)
        	{
        		if(message)
        		{
        			message.jss = pageBusUtil.pageBusJSS;
        			message.jssv = pageBusUtil.pageBusMessageVersion;
        			pageBusUtil.getPageBus().publish(subject, message);
        		}
        		else
        		{ jsx3.log("PageBusUtils: Unable to publish null message on subject \"" + subject + "\""); }
            }
            else
            { jsx3.log("PageBusUtils: subject must be specified"); }
        }
        
        /**
         *  Subscribes the callbackFunction to the subject
         *  @param subject the subject to subscribe to
         *  @param callbackFunction the function to invoke when a message is posted on the subject
         *  @param subscriberData the data object sent as an argument when the callbackFunction is invoked
         */
        pageBusUtil.subscribe = function(subject, callbackFunction, subscriberData) {
        	var subscription = pageBusUtil.getPageBus().subscribe(subject, callbackFunction, subscriberData);
        	if(pageBusUtil.subscriptionList == null)
        	{ pageBusUtil.subscriptionList = new jsx3.util.List(); }
        	pageBusUtil.subscriptionList.add(subscription);
        }
        
	/**
         *  Not for public consumption
         */
        pageBusUtil.removeAllSubscriptions = function() {
        	if(pageBusUtil.subscriptionList)
        	{
        		var pageBus = pageBusUtil.getPageBus();
        		for(i = 0; i < pageBusUtil.subscriptionList.size(); i++)
        		{
        			var subscription = pageBusUtil.subscriptionList.get(i);
        			pageBus.unsubscribe(subscription);
        		}
        		pageBusUtil.subscriptionList = null;
        	}
        }

	}
);